package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Depot;
import cn.wolfcode.crm.query.JSONResult;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IDepotService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("depot")
public class DepotController {

    @Autowired
    private IDepotService depotService;

    //由于dataGrid组件返回必须为json,所以跳转界面就分开
    @RequestMapping("view")
    public String view(){
        return "depot";
    }

    //仓库编辑界面需要
    @RequestMapping("list")
    @ResponseBody
    public List<Depot> list(){
        return depotService.selectAll();
    }

    //页面数据
    @RequestMapping("query")
    @ResponseBody
    public PageResult query(QueryObject qo){
        return depotService.query(qo);
    }


    //编辑
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(Depot depot){
        JSONResult result = new JSONResult();
        try{
            depotService.saveOrUPdate(depot);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    @RequestMapping("changeState")
    @ResponseBody
    public JSONResult changeState(Long id){
        try {
            depotService.changeState(id);
            return new JSONResult();
        }catch (Exception e){
            e.printStackTrace();
            return new JSONResult().mark("操作失败");
        }
    }
}
